<?xml version="1.0"?>
<xsl:stylesheet version="1.0" 
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
		xmlns:bridge="http://www.thomasoandrews.com/xmlns/bridge"
		xmlns:trans="http://www.thomasoandrews.com/xmlns/bridge/trans"
                exclude-result-prefixes="trans bridge">

<!-- Copyright 2002, Thomas Andrews, thomaso@best.com -->
<xsl:import href="shared.xsl"/>

<xsl:output method="html" encoding="utf-8" doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"/>

<xsl:variable name="dest"><xsl:value-of select="/bridge:book/@dest"/></xsl:variable>
<xsl:variable name="site">http://bridge.thomasoandrews.com</xsl:variable>

<xsl:variable name="booktitle"><xsl:value-of select="/bridge:book/bridge:booktitle"/></xsl:variable>

<xsl:variable name="copyright">&#169; <xsl:value-of select="/bridge:book/bridge:copyright"/></xsl:variable>

<xsl:variable name="signature">
<div class="signature">
<xsl:value-of select="/bridge:book/bridge:author"/>
(<a><xsl:attribute name="href">mailto:<xsl:value-of select="/bridge:book/bridge:author/@email"/></xsl:attribute>
<xsl:value-of select="/bridge:book/bridge:author/@email"/></a>),
<xsl:value-of select="$copyright"/>.
</div>
</xsl:variable>

<xsl:template match="/">

<html>
<head>
<xsl:copy-of select="$shortcuticon"/>
<link rel="stylesheet" type="text/css" href="../article.css"/>
<title>
<xsl:copy-of select="$booktitle"/>
</title>
</head>
<body class='print'>

<div id="body">
<h1 class="booktitle"><xsl:value-of select="$booktitle"/></h1>
<xsl:apply-templates select="bridge:book/bridge:chapter|bridge:book/bridge:article"/>
</div>
<!-- <xsl:copy-of select="$signature"/> -->
</body>
</html>

</xsl:template>

<xsl:template match="bridge:article[@href]">
<xsl:call-template name="article">
<xsl:with-param name="article" select="document(concat('xml/',$dest,'/',@href,'.xml'))/bridge:article"/>
<xsl:with-param name="name"  select="@href"/>
</xsl:call-template>
</xsl:template>

<xsl:template match="bridge:article">
<div class="body">
<xsl:apply-templates select="bridge:title"/>
<xsl:apply-templates select="bridge:body"/> 
</div>
</xsl:template>

<xsl:template match="bridge:chapter">
<h2><xsl:value-of select="bridge:title"/></h2>
<xsl:apply-templates select="bridge:article"/>
</xsl:template>

<xsl:template name="article">
<xsl:param name="article"/>
<xsl:param name="name"/>

<xsl:variable name="title"><xsl:value-of select="$article/bridge:title"/></xsl:variable>

<xsl:message>
Handling <xsl:value-of select="$name"/> (<xsl:value-of select="$title"/>)
</xsl:message>
<div id="{$name}" class="article">
<xsl:apply-templates select="$article"/>
</div>
</xsl:template>

<xsl:template match="bridge:link[@internal]">
<a href='#{@internal}'>
<xsl:apply-templates/>
</a>
</xsl:template>

<xsl:template match="bridge:link[@mypage]">
<a>
<xsl:attribute name="href"><xsl:value-of select="concat($site,@mypage)"/></xsl:attribute>
<xsl:apply-templates/>
</a>
</xsl:template>

</xsl:stylesheet>
